`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date: 2025/05/07 20:14:30
// Design Name: 
// Module Name: sha_alg
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//////////////////////////////////////////////////////////////////////////////////


module sha_alg #(
    parameter  WIDTH_IN = 128,
    parameter MSG_LEN_B =   512,
    parameter MSG_LEN_B1 =  512*2 
    )(
    input wire clk,
    input wire rst_n,
//    input ready224,
//    input ready256,
//    input ready384,
//    input ready512,
    input wire [WIDTH_IN-1:0] message, // 
    input wire valid,
    output  [223:0] digest_224,
    output  [255:0] digest_256,
    output  [383:0] digest_384,
    output  [511:0] digest_512,
    output  valid_out224,
    output  valid_out256,
    output  valid_out384,
    output  valid_out512,
    output done
    );
    
    integer i;
    reg [MSG_LEN_B - 1:0] message_block;//224/256
    reg [MSG_LEN_B1 - 1:0] message_block1;//384/512 
    wire valid224,valid256,valid384,valid512;
    
    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            message_block <= 'd0;
            message_block1 <= 'd0;
        end else begin            
            message_block[MSG_LEN_B-1:MSG_LEN_B-WIDTH_IN] <= message; 
            message_block[MSG_LEN_B-WIDTH_IN-1] <= 1'b1;
            message_block[MSG_LEN_B-WIDTH_IN-2:64] <= 'h0;
            message_block[63:0] <= WIDTH_IN;
            
            message_block1[MSG_LEN_B1-1:MSG_LEN_B1-WIDTH_IN] <= message; 
            message_block1[MSG_LEN_B1-WIDTH_IN-1] <= 1'b1;
            message_block1[MSG_LEN_B1-WIDTH_IN-2:128] <= 'h0;
            message_block1[127:0] <= WIDTH_IN;
        end
    end

//`ifdef SHA2_224
sha2_224 #(
    .MAX_MSG_LEN(MSG_LEN_B)
    )sha2_224(
        .clk            (clk          ),
        .rst_n          (rst_n        ),
//        .ready          (ready224   ),
        .message_block  (message_block),            // 
        .valid          (valid        ),
        .valid_o          (valid_out224        ),
        .digest         (digest_224       ),            //224
        .done           (         )
    );
    
//    `elsif SHA2_256


    hash256 #(
    .MAX_MSG_LEN(MSG_LEN_B)
    )sha2_256(
        .clk            (clk          ),
        .rst_n          (rst_n        ),
//        .ready          (ready256   ),
        .message_block  (message_block),            // 
        .valid          (valid        ),
        .digest         (digest_256       ),            //256
        .valid_o        (valid_out256        ),
        .done           (done         )
    );
    
    
    
//    `elsif SHA2_384
    sha2_384 #(
    .MAX_MSG_LEN(MSG_LEN_B1)
    )sha2_384(
        .clk            (clk          ),
        .rst_n          (rst_n        ),
//        .ready          (ready384   ),
        .message_block  (message_block1),            // 
        .valid          (valid        ),
        .valid_o          (valid_out384        ),
        .digest         (digest_384       ),            //384
        .done           (         )
    );
    
//    `elsif SHA2_512
    sha2_512 #(
    .MAX_MSG_LEN(MSG_LEN_B1)
    )sha2_512(
        .clk            (clk          ),
        .rst_n          (rst_n        ),
//        .ready          (ready512   ),
        .message_block  (message_block1),            // 
        .valid          (valid        ),
        .valid_o          (valid_out512        ),
        .digest         (digest_512       )
    );

    
endmodule
